// packageG/mycomponent/integral/integral.js
const app = getApp();
Component({
  /**
   * 组件的属性列表
   */
  properties: {
    datas: {
      type: null
    },
    component_id: {
      type: null
    },
    page_id: {
      type: null
    }
  },

  /**
   * 组件的初始数据
   */
  data: {

  },
  lifetimes: {
    attached: function () {
      let value = wx.getStorageSync('integral');
      this.setData({
        integral: value
      })
    }
  },
  /**
   * 组件的方法列表
   */
  methods: {
    toIntegralList() {
      wx.navigateTo({
        url: '/packageB/member/integrallist/integrallist',
      })
    },
    toIntegralDetail() {
      wx.navigateTo({
        url: '/packageB/member/integral/integral',
      })
    },
    toBack() {
      wx.navigateBack({
        delta: 1
      })
    },
    toMember() {
      wx.reLaunch({
        url: '/packageG/member_v2/member_v2',
      })
    },
    toSearch(){
      wx.navigateTo({
        url:"/packageB/member/category/search_v2/search_v2"
      })
    },
    toLink(e) {
      let {
        link
      } = this.data.datas;
      if (link.is_h5 == '2') {
        if (link.gh_id) {
          if (link.minApp_link) {
            try {
              wx.navigateToMiniProgram({
                appId: item.gh_id,
                path: item.minApp_link,
                extraData: {},
                envVersion: "release",
                success(res) {
                  // 打开成功
                },
                fail(res) {
                  wx.showToast({
                    title: "小程序跳转失败",
                    icon: "none",
                    duration: 2000,
                  });
                },
              });
            } catch (error) {
              wx.showToast({
                title: "小程序跳转失败",
                icon: "none",
                duration: 2000,
              });
            }
          } else {
            wx.showToast({
              title: "请设置跳转小程序后的跳转链接",
              icon: "none",
              duration: 2000,
            });
          }
        } else {
          wx.showToast({
            title: "请设置小程序所需跳转appId",
            icon: "none",
            duration: 2000,
          });
        }
      }else if (link.is_h5 == '1'){
        if(app._isTextEmpty(link.link)){
          wx.showToast({
            title: "请设置跳转小程序后的跳转链接",
            icon: "none",
            duration: 2000,
          });
          return
        }
        wx.navigateTo({
          url: `${link.link}`,
          fail:function(err){
            console.log('errrrrr')
            wx.reLaunch({
              url: `${link.link}`,
              fail:function(err){
                app.tips('请设置正确的跳转链接')
              }
            })
          }
        })
      }
    }
  }
})